//GALocalizationHandler.getRelativeString(Core.Localization.getString("TZ_MESSAGE_OFFERS_COINS_BUCKS"),[totalBucksDiff]);
exports.MMStoreAttributeWindow = GL2.Node.subclass(
{
    classname: 'MMStoreAttributeWindow',
    
    initialize: function(storeContainer) 
    {
		this._backgroundImage = null;
		this._closeButton = null;
		this._storeName = null;
		this._removeStoreButton = null;
		this._storeContainer = storeContainer;
		this._storeModel = storeContainer.getModelObject();
    },
	
	createView: function() 
	{
		this.makeTouchSwallower();
		
		var backgroundImagePath = this.getBaseResourcePath() + "background.png";
		
		var closeButtonImageNormal = this.getBaseResourcePath() + "close-button-normal.png";
		var closeButtonImagePressed = this.getBaseResourcePath() + "close-button-pressed.png";
		
		var genericButtonNormalImagePath = this.getBaseResourcePath() + "generic-button-normal.png";
		var genericButtonSelectedImagePath = this.getBaseResourcePath() + "generic-button-pressed.png";
		
		var fillerBarHolderImagePath = this.getBaseResourcePath() + "filler-bar-holder.png";
		var fillerBarImagePath = this.getBaseResourcePath() + "filler-bar.png";
		
		var instantRestockImagePathNormal = this.getBaseResourcePath() + "instant-finish-restock-normal.png";
		var instantRestockImagePathPressed = this.getBaseResourcePath() + "instant-finish-restock-pressed.png";
		
		var instantUpgradeImagePathNormal = this.getBaseResourcePath() + "instant-finish-upgrade-normal.png";
		var instantUpgradeImagePathPressed = this.getBaseResourcePath() + "instant-finish-upgrade-pressed.png";
			
		this._backgroundImage = GLFactory.getSprite([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(45)], null, backgroundImagePath, [TCUtil.getAdjustedX(320),TCUtil.getAdjustedY(380)]);
		this.addChild(this._backgroundImage);
		
		this._storeName = GLFactory.getText([TCUtil.getAdjustedX(110), TCUtil.getAdjustedY(30)], 100, this._storeModel.getName(), [TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(50)], TCUtil.getAdjustedFontSize(120), null, null, GL2.Text.OverflowMode.ReduceFontSize, [0.0, 0.5], new Core.Color(0,0,0));
		this._backgroundImage.addChild(this._storeName);
		
		if(TutorialManager.getHasCompletedTutorial())
		{ 
			this._closeButton = new GLButton(closeButtonImageNormal, closeButtonImagePressed, TCUtil.getAdjustedX(40),TCUtil.getAdjustedY(40), this.onCloseTouch.bind(this), this._backgroundImage, 3, "", null, null, null,null);
			this._closeButton.setPosition(TCUtil.getAdjustedX(280), TCUtil.getAdjustedY(25));
			
			//this._removeStoreButton = new GLButton(genericButtonNormalImagePath, genericButtonSelectedImagePath, TCUtil.getAdjustedX(100),TCUtil.getAdjustedY(40), this.onCloseTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("REMOVE_SHOP"),new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(90));
			//this._removeStoreButton.setPosition(TCUtil.getAdjustedX(70), TCUtil.getAdjustedY(140));
		}
		else
		{
			if(TutorialManager.getCurrentTutorialStep() == 3 || TutorialManager.getCurrentTutorialStep() == 5)
			{
				this._closeButton = new GLButton(closeButtonImageNormal, closeButtonImagePressed, TCUtil.getAdjustedX(40),TCUtil.getAdjustedY(40), this.onCloseTouch.bind(this), this._backgroundImage, 3, "", null, null, null,null);
				this._closeButton.setPosition(TCUtil.getAdjustedX(280), TCUtil.getAdjustedY(25));
			}			
		}

		this._thumbImage = GLFactory.getSprite([TCUtil.getAdjustedX(25),TCUtil.getAdjustedY(50)], null, this._storeContainer.getThumbImagePath(), [TCUtil.getAdjustedX(90),TCUtil.getAdjustedY(58)]);
		this._backgroundImage.addChild(this._thumbImage);	
		
		this._storeDescription = GLFactory.getText([TCUtil.getAdjustedX(127), TCUtil.getAdjustedY(80)], 100, GALocalizationHandler.getRelativeString(Core.Localization.getString("COIN_GENERATION_PER_CUSTOMER"),[this._storeModel.getRewardAmount()]), [TCUtil.getAdjustedX(170), TCUtil.getAdjustedY(100)], TCUtil.getAdjustedFontSize(120), null, null, GL2.Text.OverflowMode.Multiline, [0.0, 0.5], new Core.Color(0,0,0));
		this._backgroundImage.addChild(this._storeDescription);		
		
		this.drawRequiredUI();
	},
	
	makeTouchSwallower: function()
    {
    	var width = 0 , height = 0;
    	width = Core.Capabilities.getScreenWidth();
		height = Core.Capabilities.getScreenHeight();
        
    	this._dissolveTouchesTarget = new GL2.TouchTarget();
    	this._dissolveTouchesTarget.setAnchor(0,0);
		this._dissolveTouchesTarget.setSize(TCUtil.getAdjustedX(width),TCUtil.getAdjustedY(height));
        this._dissolveTouchesTarget.setPosition(TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(0));
     
        this._myMessageListener = new Core.MessageListener();
		this._dissolveTouchesTarget.getTouchEmitter().addListener(this._myMessageListener, this.dissolveTouches.bind(this),10); //@ make this 10 go to Constants.
		this.addChild(this._dissolveTouchesTarget);
    },
        
    dissolveTouches: function()
    {
    	return true;
    },
    
    drawRequiredUI: function()
    {
    	if(TutorialManager.getHasCompletedTutorial())
    	{
    		this.drawRequiredUpgradeUI();
    		this.drawRequiredRestockUI();
    	}
    	else 
    	{
    		if(TutorialManager.getCurrentTutorialStep() == 2)
    		{
    			this.drawRequiredRestockUI();
    			
    			var tutorialIndicator = this._storeContainer._tutorialIndicatorForRestock;
    			if(tutorialIndicator)
				{
					tutorialIndicator.setPosition([TCUtil.getAdjustedX(240), TCUtil.getAdjustedY(260)]);
					TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(120),TCUtil.getAdjustedY(45)]);
					TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_2"));
				}    			
    		}
    		
    		else if(TutorialManager.getCurrentTutorialStep() == 3)
    		{
    			this.drawRequiredRestockUI();
    			
				var tutorialIndicator = this._storeContainer._tutorialIndicatorForInstantRestock;
				if(tutorialIndicator)
				{
					tutorialIndicator.setPosition([TCUtil.getAdjustedX(240), TCUtil.getAdjustedY(265)]);
					TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(55),TCUtil.getAdjustedY(285)]);
					TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_3"));
				}    			
    		}
    		else if(TutorialManager.getCurrentTutorialStep() == 4)
    		{
    			this.drawRequiredUpgradeUI();
    			
				var tutorialIndicator = this._storeContainer._tutorialIndicatorForUpgrade;
				if(tutorialIndicator)
				{
					tutorialIndicator.setPosition([TCUtil.getAdjustedX(240), TCUtil.getAdjustedY(305)]);
					TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(120),TCUtil.getAdjustedY(90)]);
					TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_4"));
				}    			
    		}
    		else if(TutorialManager.getCurrentTutorialStep() == 5)
    		{
    			this.drawRequiredUpgradeUI();
    			
				var tutorialIndicator = this._storeContainer._tutorialIndicatorForInstantUpgrade;
				if(tutorialIndicator)
				{
					tutorialIndicator.setPosition([TCUtil.getAdjustedX(240), TCUtil.getAdjustedY(375)]);
					TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(120),TCUtil.getAdjustedY(110)]);
					TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_5"));
				}    			
    		}
    	}
    },
	
	drawRequiredUpgradeUI: function()
	{
		this.removeUpgradeUI();

		if(this._redrawUpgradeUITimeout)
		{
			clearTimeout(this._redrawUpgradeUITimeout);
			this._redrawUpgradeUITimeout = null;
		}		
		this._storeDescription.setText(GALocalizationHandler.getRelativeString(Core.Localization.getString("COIN_GENERATION_PER_CUSTOMER"),[this._storeModel.getRewardAmount()]));
		this._upgradeLabel = GLFactory.getText([TCUtil.getAdjustedX(55), TCUtil.getAdjustedY(270)], 100, GALocalizationHandler.getRelativeString(Core.Localization.getString("GRADE"),[this._storeModel.getUpgradeState() + 1]), [TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(50)], TCUtil.getAdjustedFontSize(120), null, null, GL2.Text.OverflowMode.ReduceFontSize, [0.0, 0.5], new Core.Color(0,0,0));
		this._backgroundImage.addChild(this._upgradeLabel);
		if(this._storeModel.canUpgradeStore())
		{												
			if(!this._storeModel.isUpgradeInProgress() )
			{			 											
				var genericButtonNormalImagePath = this.getBaseResourcePath() + "generic-button-normal.png";
				var genericButtonSelectedImagePath = this.getBaseResourcePath() + "generic-button-pressed.png";
				
				if(this._upgradeButton)
				{
					this._upgradeButton.destroy();
					this._upgradeButton = null;						
				}
						
				this._upgradeButton = new GLButton(genericButtonNormalImagePath, genericButtonSelectedImagePath, TCUtil.getAdjustedX(100),TCUtil.getAdjustedY(40), this.onUpgradeButtonTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("UPGRADE"),new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(90));
				this._upgradeButton.setPosition(TCUtil.getAdjustedX(215), TCUtil.getAdjustedY(270));
			}
			else 
			{
				this._upgradeLabel.setPosition([TCUtil.getAdjustedX(18), TCUtil.getAdjustedY(290)]);
				this.createUpgradeUI();
				this.refreshUpdateFillerBarFrame();					
				this._redrawUpgradeUITimeout = setTimeout(this.drawRequiredUpgradeUI.bind(this), this._storeModel.upgradeRemainingTime()*1000);				
			}
		}
		else
		{
			this._upgradeLabel.setPosition([TCUtil.getAdjustedX(110), TCUtil.getAdjustedY(270)]);
		}
	},
	
	createUpgradeUI: function()
	{
		var fillerBarHolderImagePath = this.getBaseResourcePath() + "filler-bar-holder.png";
		var fillerBarImagePath = this.getBaseResourcePath() + "filler-bar.png";

		var instantUpgradeImagePathNormal = this.getBaseResourcePath() + "instant-finish-upgrade-normal.png";
		var instantUpgradeImagePathPressed = this.getBaseResourcePath() + "instant-finish-upgrade-pressed.png";
		
		//this.removeUpgradeUI();
		
//		this._upgradeLabel = GLFactory.getText([TCUtil.getAdjustedX(18), TCUtil.getAdjustedY(290)], 100,"Grade "+(this._storeModel.getUpgradeState() + 1), [TCUtil.getAdjustedX(120), TCUtil.getAdjustedY(50)], TCUtil.getAdjustedFontSize(130), null, null, GL2.Text.OverflowMode.ReduceFontSize, [0.0, 0.5], new Core.Color(0,0,0));
//		this._backgroundImage.addChild(this._upgradeLabel);
				
		this._upgradeFillerBarHolder = GLFactory.getSprite([TCUtil.getAdjustedX(120),TCUtil.getAdjustedY(260)], null, fillerBarHolderImagePath, [TCUtil.getAdjustedX(170),TCUtil.getAdjustedY(50)]);
		this._backgroundImage.addChild(this._upgradeFillerBarHolder);				
		
		this._upgradeFillerBar = GLFactory.getSprite([TCUtil.getAdjustedX(11),TCUtil.getAdjustedY(4)], null, fillerBarImagePath, [TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(37)]);///x=159 for full
		this._upgradeFillerBarHolder.addChild(this._upgradeFillerBar);
		
		this._upgradingLabel = GLFactory.getText([TCUtil.getAdjustedX(11), TCUtil.getAdjustedY(4)], 100, Core.Localization.getString("UPGRADING"), [TCUtil.getAdjustedX(150), TCUtil.getAdjustedY(40)], TCUtil.getAdjustedFontSize(130), null, null, GL2.Text.OverflowMode.ReduceFontSize, [0.0, 0.0], new Core.Color(0,0,0));
		this._upgradeFillerBarHolder.addChild(this._upgradingLabel);
		
		this._instantUpgradingButton = new GLButton(instantUpgradeImagePathNormal, instantUpgradeImagePathPressed, TCUtil.getAdjustedX(260),TCUtil.getAdjustedY(40), this.onInstantUpgradeTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("INSTANT_FINISH_UPGRADE"),new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(90));
		this._instantUpgradingButton.setPosition(TCUtil.getAdjustedX(165), TCUtil.getAdjustedY(335));	
	},
	
	removeUpgradeUI: function()
	{
		if(this._upgradeFillerBarUpdateTimeout)
		{
			clearTimeout(this._upgradeFillerBarUpdateTimeout);
			this._upgradeFillerBarUpdateTimeout = null;
		}	
		if(this._upgradeFillerBarHolder)
		{
			this._upgradeFillerBarHolder.destroy();
			this._upgradeFillerBarHolder = null;						
		}
		if(this._upgradeLabel)
		{
			this._upgradeLabel.destroy();
			this._upgradeLabel = null;						
		}
		if(this._upgradeFillerBar)
		{
			this._upgradeFillerBar.destroy();
			this._upgradeFillerBar = null;
			
			if(!TutorialManager.getHasCompletedTutorial())
			{
				this.onCloseTouch();
			}
		}
		if(this._upgradingLabel)
		{
			this._upgradingLabel.destroy();
			this._upgradingLabel = null;						
		}		
		if(this._instantUpgradingButton)
		{
			this._instantUpgradingButton.destroy();
			this._instantUpgradingButton = null;
		}
	},
	//storeContainer.getModelObject().getUpgradePricing();
	drawRequiredRestockUI: function()
	{
		this.removeRestockUI();
		
		if(this._redrawRestockUITimeout)
		{
			clearTimeout(this._redrawRestockUITimeout);
			this._redrawRestockUITimeout = null;
		}		
		
		this._stockLabel = GLFactory.getText([TCUtil.getAdjustedX(60), TCUtil.getAdjustedY(215)], 100, GALocalizationHandler.getRelativeString(Core.Localization.getString("STOCK_PERCENT"),[this._storeModel.getRemainingStockInPercentage()]), [TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(50)], TCUtil.getAdjustedFontSize(120), null, null, GL2.Text.OverflowMode.ReduceFontSize, [0.0, 0.5], new Core.Color(0,0,0));
		this._backgroundImage.addChild(this._stockLabel);
		
		if(this._storeModel.canRestockStore())
		{
			if(!this._storeModel.isRestockInProgress())
			{			 											
				if(this._restockButton)
				{
					this._restockButton.destroy();
					this._restockButton = null;						
				}
				
				var genericButtonNormalImagePath = this.getBaseResourcePath() + "generic-button-normal.png";
				var genericButtonSelectedImagePath = this.getBaseResourcePath() + "generic-button-pressed.png";						
				this._restockButton = new GLButton(genericButtonNormalImagePath, genericButtonSelectedImagePath, TCUtil.getAdjustedX(100),TCUtil.getAdjustedY(40), this.onRestockButtonTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("RESTOCK"),new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(90));
				this._restockButton.setPosition(TCUtil.getAdjustedX(215), TCUtil.getAdjustedY(220));
			}
			else 
			{
				this._stockLabel.setPosition([TCUtil.getAdjustedX(18), TCUtil.getAdjustedY(180)]);
				
				this.createRestockUI();
				this.refreshRestockFillerBarFrame();				
				this._redrawRestockUITimeout = setTimeout(this.drawRequiredRestockUI.bind(this), this._storeModel.restockRemainingTime()*1000);				
			}
		}
		else
		{
			this._stockLabel.setText(GALocalizationHandler.getRelativeString(Core.Localization.getString("STOCK_PERCENT"),[this._storeModel.getRemainingStockInPercentage()]));
			this._stockLabel.setPosition([TCUtil.getAdjustedX(110), TCUtil.getAdjustedY(200)]);
		}		
	},
	
	createRestockUI: function()
	{
		var fillerBarHolderImagePath = this.getBaseResourcePath() + "filler-bar-holder.png";
		var fillerBarImagePath = this.getBaseResourcePath() + "filler-bar.png";
		
		var instantRestockImagePathNormal = this.getBaseResourcePath() + "instant-finish-restock-normal.png";
		var instantRestockImagePathPressed = this.getBaseResourcePath() + "instant-finish-restock-pressed.png";
	
		this._restockFillerBarHolder = GLFactory.getSprite([TCUtil.getAdjustedX(120),TCUtil.getAdjustedY(155)], null, fillerBarHolderImagePath, [TCUtil.getAdjustedX(170),TCUtil.getAdjustedY(50)]);
		this._backgroundImage.addChild(this._restockFillerBarHolder);				
		
		this._restockFillerBar = GLFactory.getSprite([TCUtil.getAdjustedX(11),TCUtil.getAdjustedY(4)], null, fillerBarImagePath, [TCUtil.getAdjustedX(100),TCUtil.getAdjustedY(37)]);///x=159 for full
		this._restockFillerBarHolder.addChild(this._restockFillerBar);
		
		this._restockingLabel = GLFactory.getText([TCUtil.getAdjustedX(11), TCUtil.getAdjustedY(4)], 100, Core.Localization.getString("RESTOCKING"), [TCUtil.getAdjustedX(150), TCUtil.getAdjustedY(40)], TCUtil.getAdjustedFontSize(130), null, null, GL2.Text.OverflowMode.ReduceFontSize, [0.0, 0.0], new Core.Color(0,0,0));
		this._restockFillerBarHolder.addChild(this._restockingLabel);
		
		this._instantRestockingButton = new GLButton(instantRestockImagePathNormal, instantRestockImagePathPressed, TCUtil.getAdjustedX(260),TCUtil.getAdjustedY(40), this.onInstantRestockTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("INSTANT_FINISH_RESTOCK"),new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(90));
		this._instantRestockingButton.setPosition(TCUtil.getAdjustedX(165), TCUtil.getAdjustedY(230));
	},
	
	removeRestockUI: function()
	{
		if(this._restockFillerBarUpdateTimeout)
		{
			clearTimeout(this._restockFillerBarUpdateTimeout);
			this._restockFillerBarUpdateTimeout = null;
		}
		if(this._stockLabel)
		{
			this._stockLabel.destroy();
			this._stockLabel = null;
		}
		if(this._restockFillerBarHolder)
		{
			this._restockFillerBarHolder.destroy();
			this._restockFillerBarHolder = null;
		}
		if(this._restockFillerBar)
		{
			this._restockFillerBar.destroy();
			this._restockFillerBar = null;
			if(!TutorialManager.getHasCompletedTutorial())
			{
				this.onCloseTouch();
			}
		}
		if(this._restockingLabel)
		{
			this._restockingLabel.destroy();
			this._restockingLabel = null;
		}
		if(this._instantRestockingButton)
		{
			this._instantRestockingButton.destroy();
			this._instantRestockingButton = null;
		}
	},
	
	onUpgradeButtonTouch: function()
	{
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		this._storeContainer.upgradeStore();
		this.destroy();
		//this.createUpgradeUI();
	},
	
	onRestockButtonTouch: function()
	{
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		this._storeContainer.restockStore();		
		this.destroy();		
	},
	
	onInstantUpgradeTouch: function()
	{
		// TODO VALID PURCHASE CHECK :(
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		if(this._storeContainer._storeModel.canUpgradeBePurchased(kCurrencyType.kCurrencyTypeNuggets,3))
		{
			if(this._storeContainer._upgradeTimeout)
			{
				clearTimeout(this._storeContainer._upgradeTimeout);
				this._storeContainer.upgradeDoneCallBack();
				MMGameState.getCurrentUser().updateCurrency(kOperationType.kOperationSubtractNuggets, 3);
				//AnalyticsHandler.logInstantComplete("InstantUpgrade",3);
				AnalyticsHandler.logAnalyticsOffer("InstantUpgrade", 3 , "Nuggets",this._storeContainer._storeModel.getItemId());
				this.destroy();
			}
		}
		else
		{
			//TODO Put Alert something to show user that he/she dont have enough currency to do action
			var alertBox = UIFactory.getAlertBox(Core.Localization.getString("MESSAGE"), Core.Localization.getString("NOT_ENOUGH_MONEY"), ["ok"], this);
		}
	},
	
	onInstantRestockTouch: function()
	{
		//TODO VALID PURCHASE CHECK 
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		if(this._storeContainer._storeModel.canUpgradeBePurchased(kCurrencyType.kCurrencyTypeNuggets,3))
		{
			if(this._storeContainer._restockTimeout)
			{
				clearTimeout(this._storeContainer._restockTimeout);
				this._storeContainer.restockDoneCallBack();
				MMGameState.getCurrentUser().updateCurrency(kOperationType.kOperationSubtractNuggets, 3);
				//AnalyticsHandler.logInstantComplete("InstantRestock",3);
				AnalyticsHandler.logAnalyticsOffer("InstantRestock", 3 , "Nuggets",this._storeContainer._storeModel.getItemId());
				this.destroy();
			}
		}
		else
		{
			//TODO Put Alert something to show user that he/she dont have enough currency to do action
			var alertBox = UIFactory.getAlertBox(Core.Localization.getString("MESSAGE"), Core.Localization.getString("NOT_ENOUGH_MONEY"), ["ok"], this);
		}
	},	
	
	onCloseTouch: function ()
	{
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		if(!TutorialManager.getHasCompletedTutorial())
		{
			if(TutorialManager.getCurrentTutorialStep() == 3)
			{
				var tutorialIndicator = this._storeContainer._tutorialIndicatorForInstantRestock;
				if(tutorialIndicator)
				{
					tutorialIndicator.setPosition([TCUtil.getAdjustedX(95), TCUtil.getAdjustedY(365)]);
					TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(70),TCUtil.getAdjustedY(160)]);	
					TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_3"));				
				}
			}
			else if(TutorialManager.getCurrentTutorialStep() == 5)
			{
				var tutorialIndicator = this._storeContainer._tutorialIndicatorForInstantUpgrade;
				if(tutorialIndicator)
				{
					tutorialIndicator.setPosition([TCUtil.getAdjustedX(95), TCUtil.getAdjustedY(365)]);
					TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(35),TCUtil.getAdjustedY(160)]);
					TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_5"));
				}
			}
		}		
		this.destroy();
	},
	
	refreshUpdateFillerBarFrame: function()
	{
		var fillerBarImagePath = this.getBaseResourcePath() + "filler-bar.png";
		var upgradeFillerBarFrameRatio = this._storeModel.getUpgradeProgressPercentage()/100;
		this._upgradeFillerBar.setImage(fillerBarImagePath, [TCUtil.getAdjustedX(159*upgradeFillerBarFrameRatio),TCUtil.getAdjustedY(37)], [0, 0]);
		this._upgradeFillerBarUpdateTimeout = setTimeout(this.refreshUpdateFillerBarFrame.bind(this), 500);
	},
	
	refreshRestockFillerBarFrame: function()
	{
		var fillerBarImagePath = this.getBaseResourcePath() + "filler-bar.png";
		var restockFillerBarFrameRatio = this._storeModel.getRestockProgressPercentage()/100;
		//console.log("zzz::::: ratio is"+ upgradeFillerBarFrameRatio);
		this._restockFillerBar.setImage(fillerBarImagePath, [TCUtil.getAdjustedX(159*restockFillerBarFrameRatio),TCUtil.getAdjustedY(37)], [0, 0]);
		this._restockFillerBarUpdateTimeout = setTimeout(this.refreshRestockFillerBarFrame.bind(this), 500);
	},
		
	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/attributewindow/";
	},
	
	destroy: function ()
	{	
		//UPGRADE UI
		if(this._upgradeFillerBarUpdateTimeout)
		{
			clearTimeout(this._upgradeFillerBarUpdateTimeout);
			this._upgradeFillerBarUpdateTimeout = null;
		}
		if(this._redrawUpgradeUITimeout)
		{
			clearTimeout(this._redrawUpgradeUITimeout);
			this._redrawUpgradeUITimeout = null;
		}		
		if(this._upgradeButton)
		{
			this._upgradeButton.destroy();
			this._upgradeButton = null;						
		}
		if(this._upgradeFillerBarHolder)
		{
			this._upgradeFillerBarHolder.destroy();
			this._upgradeFillerBarHolder = null;						
		}
		if(this._upgradeLabel)
		{
			this._upgradeLabel.destroy();
			this._upgradeLabel = null;						
		}
		if(this._upgradeFillerBar)
		{
			this._upgradeFillerBar.destroy();
			this._upgradeFillerBar = null;						
		}
		if(this._upgradingLabel)
		{
			this._upgradingLabel.destroy();
			this._upgradingLabel = null;						
		}		
		if(this._instantUpgradingButton)
		{
			this._instantUpgradingButton.destroy();
			this._instantUpgradingButton = null;
		}	
		
		//RESTOCK UI	
		if(this._restockFillerBarUpdateTimeout)
		{
			clearTimeout(this._restockFillerBarUpdateTimeout);
			this._restockFillerBarUpdateTimeout = null;
		}
		if(this._redrawRestockUITimeout)
		{
			clearTimeout(this._redrawRestockUITimeout);
			this._redrawRestockUITimeout = null;
		}			
		if(this._stockLabel)
		{
			this._stockLabel.destroy();
			this._stockLabel = null;
		}
		if(this._restockFillerBarHolder)
		{
			this._restockFillerBarHolder.destroy();
			this._restockFillerBarHolder = null;
		}
		if(this._restockFillerBar)
		{
			this._restockFillerBar.destroy();
			this._restockFillerBar = null;
		}
		if(this._restockingLabel)
		{
			this._restockingLabel.destroy();
			this._restockingLabel = null;
		}
		if(this._instantRestockingButton)
		{
			this._instantRestockingButton.destroy();
			this._instantRestockingButton = null;
		}
		
		//MAIN UI
		if(this._backgroundImage)
		{
			this._backgroundImage.destroy();
			this._backgroundImage = null;
		}
		if(this._closeButton)
		{
			this._closeButton.destroy();
			this._closeButton = null;
		}
		if(this._storeName)
		{
			this._storeName.destroy();
			this._storeName = null;
		}
		if(this._dissolveTouchesTarget)
		{
			this._dissolveTouchesTarget.destroy();
			this._dissolveTouchesTarget = null;
		}
		if(this._myMessageListener)
		{
			this._myMessageListener.destroy();
			this._myMessageListener = null;
		}
		if(this._removeStoreButton)
		{
			this._removeStoreButton.destroy();
			this._removeStoreButton = null;
		}
	}
});